#include "SysCommons.h"
#include "Element.h"
#include "Caption.h"
#include "Tr.h"
#include "Sorter.h"

int getElementOrder(Element *e) {
	if(typeid(*e) == typeid(Caption))
		return 0;
	else if(typeid(*e) == typeid(Tr)) {
		Tr *tr = (Tr *)e;
		return tr->getType();
	}

	return -1;
}

bool _table_children_sort(Element *e1, Element *e2) {
	int i1 = getElementOrder(e1);
	int i2 = getElementOrder(e2);

	return i1 < i2;
}

void Sorter::table_children_sort(std::list<Element *> &children) {
	children.sort(_table_children_sort);
}